//
//  HWArtificialKeFuViewController.m
//  HWanGame
//
//  Created by 陈道斌 on 2019/10/16.
//  Copyright © 2019 Chendaobin. All rights reserved.
//

#import "HWArtificialKeFuViewController.h"
#import "HWArtificialKeFuCell.h"

@interface HWArtificialKeFuViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(strong,nonatomic) UITableView *mainaTableVie;
@property(strong,nonatomic) NSDictionary *dataDic;
@end

@implementation HWArtificialKeFuViewController

-(UITableView *)mainaTableVie {
    
    if (_mainaTableVie == nil
        ) {
    
        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH-50-TabbarSafeBottomMargin) style:UITableViewStylePlain];
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        _mainaTableVie.backgroundColor = [UIColor whiteColor];
     //   _mainaTableVie.backgroundColor = RGB(228, 235, 247);
        
    
        
        
    }
    return   _mainaTableVie ;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupUI];
    

}

- (void)setupUI {
    
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"客服中心";
    [self.view addSubview:self.mainaTableVie];
    
    [self fasongwangluoqingqiu];

    
}

// 发送网路请求
- (void)fasongwangluoqingqiu {
    
      
          NSString *uidStr = [NSString stringWithFormat:@"%@",[HWLocallyStoredData getLoginUserID]];
          NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
            
    
          

        
    
       
          NSDictionary *parametes = @{
               
                                              @"ios" : @"1",
                                              @"ct" :  @"app",
                                              @"ac" : @"kefu",
                                            
                    
                                              };
              
             [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
                  
                
                  
                  NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
                  
                  if ([codeStr intValue] == 1) {
               
                      self.dataDic = response[@"data"];
                      
                  
                      [self.mainaTableVie reloadData];
           
           
                  } else {
                      
                      
                       [MBProgressHUD showError:response[@"message"]];
                      
                  }
               
                  
                  
              } failure:^(NSString *error) {
                 
                    [MBProgressHUD showError:@"发送建议失败"];
                  
              }];
       
       
    
    
}







- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
    return  2;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    static NSString *cellID = @"cellID";
    HWArtificialKeFuCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    if (!cell) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"HWArtificialKeFuCell" owner:nil options:nil].firstObject;
        
    }
   cell.selectionStyle  = UITableViewCellSelectionStyleNone;
   cell.backgroundColor = [UIColor whiteColor];
//    cell.textLabel.text = @"123";
    
    if (indexPath.row == 0 ) {
        
        cell.diyigeLabel.text = @"QQ客服";
        cell.miashuLabel.text =  self.dataDic[@"qq"];
        
        [cell.dianjiButton setTitle:@"联系客服" forState:UIControlStateNormal];
        [cell.dianjiButton addTarget:self action:@selector(dianhua) forControlEvents:UIControlEventTouchUpInside];
        cell.dianjiButton.hidden = NO;
        
        
    } else {
          cell.diyigeLabel.text = @"微信客服";
         // cell.miashuLabel.text = @"请关注微信公众号“94hwan” ";
          cell.miashuLabel.text = [NSString stringWithFormat:@"请关注微信公众号: %@",self.dataDic[@"weixinhao"]];
          [cell.dianjiButton setTitle:@"关注" forState:UIControlStateNormal];
          cell.dianjiButton.hidden = YES;
        
        
    }
    
    return  cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    return  109;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    
    return  36;
    
}


- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    UIView *hederview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 36)];
 //   hederview.backgroundColor = [UIColor redColor];
    
    UILabel *miashilabel = [[UILabel alloc]initWithFrame:CGRectMake(16, 0, kScreenW-32, 36)];
    miashilabel.font = [UIFont systemFontOfSize:12];
    miashilabel.text = @"客服在线时间9:00-18:00";
    
    miashilabel.textColor = RGB(51, 51, 51);
  //  miashilabel.backgroundColor = [UIColor yellowColor];
    
    
    [hederview addSubview:miashilabel];
    
    
    return  hederview;
    
    
}



// 电话
- (void)dianhua {
    
    
   [WMUtil  callPhoneActionWithPhoneNum:self.dataDic[@"phone"] WithViewController:self];
}


@end
